<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 订单信息搜索框 -->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrdersList">
            <el-button icon="el-icon-search" slot="append" @click="getOrdersList"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 订单列表 表单显示区域 -->
      <el-table
      :data="ordersList"
      border
      stripe>
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格(元)" prop="order_price" width="100px"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status" width="100px">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.paystatus === 1">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send" width="80px"></el-table-column>
        <el-table-column label="下单时间" prop="create_time" width="180px">
          <template slot-scope="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="190px">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox"></el-button>
            <el-button type="success" icon="el-icon-location-information" size="mini" @click="showLogistics"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页器 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 15, 20, 25]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>

    <!-- 修改地址对话框 -->
    <el-dialog
      title="添加分类"
      :visible.sync="setAddressDialogVisible"
      width="50%"
      @close="handleClosed">
      <el-form :model="addressForm" :rules="rules"
      ref="addressFormRef" label-width="100px">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :options="cityData"
            clearable
            @change="completeAddress">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2" autocomplete></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="setAddressDialogVisible = false">取 消</el-button>
        <el-button type="primary">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 物流进度对话框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="logisticsDialogVisible"
      width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in this.logisticsInfo"
          :key="index"
          size="large"
          :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
      <div slot="footer" class="dialog-footer">
        <el-button @click="logisticsDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="logisticsDialogVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'

export default {
  data () {
    return {
      // 订单列表的配置信息
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      // 获得的订单列表
      ordersList: [],
      // 订单总条数
      total: 0,
      // 修改地址对话框的显示与隐藏
      setAddressDialogVisible: false,
      // 修改地址表单校验规则
      rules: {
        address1: { required: true, message: '请选择省市区/县！', trigger: 'blur' },
        address2: { required: true, message: '请输入详细地址！', trigger: 'blur' }
      },
      addressForm: {
        address1: [],
        address2: ''
      },
      cityData,
      logisticsDialogVisible: false,
      // 物流信息
      logisticsInfo: [
        {
          time: '2020-07-15 12:39:56',
          ftime: '2020-07-15 12:39:56',
          context: '已签收,签收人是（快递已送代理点如有问题请联系11053685196）先生/女士，如有疑问请联系派件员寒亭魏飞飞(11053685196、0530-18194261)，如您未收到此快递，请拨打投诉电话：0530--17366376，感谢使用申通快递，期待再次为您服务',
          location: null
        },
        {
          time: '2020-07-15 08:46:54',
          ftime: '2020-07-15 08:46:54',
          context: '山东潍坊寒亭营业厅-寒亭魏飞飞(11053685196,0530-18194261)-派件中',
          location: null
        },
        {
          time: '2020-07-15 08:38:57',
          ftime: '2020-07-15 08:38:57',
          context: '已到达-山东潍坊寒亭营业厅',
          location: null
        },
        {
          time: '2020-07-15 06:38:13',
          ftime: '2020-07-15 06:38:13',
          context: '已到达-山东潍坊寒亭营业厅',
          location: null
        },
        {
          time: '2020-07-14 20:56:45',
          ftime: '2020-07-14 20:56:45',
          context: '山东潍坊转运中心-已发往-山东潍坊寒亭公司',
          location: null
        },
        {
          time: '2020-07-14 20:52:44',
          ftime: '2020-07-14 20:52:44',
          context: '已到达-山东潍坊转运中心',
          location: null
        },
        {
          time: '2020-07-14 17:43:48',
          ftime: '2020-07-14 17:43:48',
          context: '已到达-山东潍坊转运中心',
          location: null
        },
        {
          time: '2020-07-14 10:53:46',
          ftime: '2020-07-14 10:53:46',
          context: '山东临沂转运中心-已发往-山东潍坊转运中心',
          location: null
        },
        {
          time: '2020-07-14 10:43:31',
          ftime: '2020-07-14 10:43:31',
          context: '已到达-山东临沂转运中心',
          location: null
        },
        {
          time: '2020-07-14 02:43:20',
          ftime: '2020-07-14 02:43:20',
          context: '安徽合肥转运中心-已发往-山东临沂转运中心',
          location: null
        },
        {
          time: '2020-07-14 02:41:40',
          ftime: '2020-07-14 02:41:40',
          context: '已到达-安徽合肥转运中心',
          location: null
        },
        {
          time: '2020-07-13 16:28:13',
          ftime: '2020-07-13 16:28:13',
          context: '安徽阜阳转运中心-已发往-安徽合肥转运中心',
          location: null
        },
        {
          time: '2020-07-13 15:03:30',
          ftime: '2020-07-13 15:03:30',
          context: '安徽利辛公司-已发往-安徽阜阳转运中心',
          location: null
        },
        {
          time: '2020-07-13 14:47:56',
          ftime: '2020-07-13 14:47:56',
          context: '安徽利辛公司-已发往-安徽阜阳转运中心',
          location: null
        },
        {
          time: '2020-07-13 14:37:06',
          ftime: '2020-07-13 14:37:06',
          context: '安徽利辛公司-城南吴彦祖-已收件',
          location: null
        }
      ]
    }
  },
  created () {
    this.getOrdersList()
  },
  methods: {
    // 获取订单列表
    async getOrdersList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      this.ordersList = res.data.goods
      this.total = res.data.total
    },
    // 分页器控制表单单页显示条数
    handleSizeChange (val) {
      this.queryInfo.pagesize = val
      this.getOrdersList()
    },
    // 分页器控制表单的当前显示页面
    handleCurrentChange (val) {
      this.queryInfo.pagenum = val
      this.getOrdersList()
    },
    // 显示修改地址对话框
    showBox () {
      this.setAddressDialogVisible = true
    },
    // 关闭修改地址对话框重置输入的信息
    handleClosed () {
      this.$refs.addressFormRef.resetFields()
    },
    completeAddress () {
      const address = this.addressForm.address1.toString()
      this.addressForm.address2 = address.replace(',', '')
    },
    // 显示物流进度
    async showLogistics () {
      this.logisticsDialogVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
.el-cascader {
  width: 100%;
}
</style>
